//
//  ThemeCell.swift
//  WanAndroidLearn
//
//  Created by TRS-Mobile on 2023/11/2.
//

import Foundation
import ReactorKit
import SnapKit

class ThemeCell: TableViewBaseCell, View {
    
    lazy var titleLabel: Label = {
        let view = Label()
        view.font = view.font.withSize(14)
        return view
    }()
    
    lazy var iconView: UIBaseView = {
        let view = UIBaseView()
        return view
    }()
    
    typealias Reactor = ThemeCellReactor
    
    override func makeUI() {
        super.makeUI()
        containerView.addSubview(iconView)
        containerView.addSubview(titleLabel)
        
        iconView.snp.makeConstraints { make in
            make.left.equalToSuperview().inset(10)
            make.top.bottom.equalToSuperview().inset(10)
            make.size.equalTo(CGSize(width: 30, height: 30)).priority(.high)
        }
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconView.snp.right).offset(10)
            make.centerY.equalToSuperview()
        }
//        titleLabel.theme.textColor = themed { $0.text }
//        titleLabel.theme.textColor = themed {
//            ThemeType.currentTheme().isDark ? $0.secondaryDark : $0.secondary
//        }
    }
    
    func bind(reactor: ThemeCellReactor) {
        reactor.state
            .map { $0.title }
            .bind(to: titleLabel.rx.text)
            .disposed(by: disposeBag)
        reactor.state
            .map { $0.imageColor }
            .bind(to: iconView.rx.backgroundColor)
            .disposed(by: disposeBag)
        reactor.state
            .map { $0.imageColor }
            .bind(to: titleLabel.rx.textColor)
            .disposed(by: disposeBag)
    }
}
